1

相对路径可正常跳转

import { namespace, getStaffs as actionGetStaffs, addStaffs as actionAddStaffs } from '../../redux/actions/staff'

但是在webpack配置alias使用绝对路径后无法跳转

webpack配置:

resolve: {
       modules: [path.join(__dirname, 'src'), 'node_modules'],
       extensions: ['.js', '.jsx', '.json', '.scss', '.css'],
       alias: {
            src: path.join(__dirname, 'src'),
       },
       plugins: [
            new ModuleScopePlugin(appSrc, [appPackageJson]),
       ],
},

// 文件导入

import { namespace, getStaffs as actionGetStaffs, addStaffs as actionAddStaffs } from 'src/redux/actions/staff'

解决办法:
需要添加一个jsconfig文件,如下:

{
  "compilerOptions": {
    "baseUrl": "./",  // all paths are relative to the baseUrl
    "paths": {
        "src/*" : ["src/*"]   
    }
  }
}

参考地址:


JayChang2017
7 声望0 粉丝